package lt.laimis.shop.service.content;

import lt.laimis.shop.service.product.Product;
import lt.laimis.shop.dao.DaoNode;

import java.util.List;
import java.util.ArrayList;

/**
 * Created by IntelliJ IDEA.
 * User: laimis
 * Date: Aug 5, 2008
 * Time: 6:52:08 PM
 * To change this template use File | Settings | File Templates.
 */
public class ContentService {
    private List<Content> contentList;
    protected DaoNode daoNode;

    public void setDaoNode(DaoNode daoNode) {
        this.daoNode = daoNode;
    }

    public List<Content> getProductsList() {
        if(contentList == null && daoNode != null ){
              contentList = new ArrayList<Content>();
              contentList = daoNode.getListContent();
        }
        return contentList;
    }

    public Content getByParentId(String nodeId) {
         Content item = null;
        if (nodeId != null && getProductsList() != null) {
            for (Content content : contentList) {
                if (content.getParentId().equals(nodeId)) {
                    item = content;
                }
            }
        }
        return item;
    }
}
